package com.yuyu.shop.infrastructure.general.mq.listener;

import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Slf4j
@Component
public class OnsOrderListener implements MessageListener {

    @Override
    public Action consume(Message message, ConsumeContext consumeContext) {
        String msgId = message.getMsgID();
//      byte[] body = message.getBody();
        String s = new String(message.getBody(), StandardCharsets.UTF_8);
        log.info("topic接收到消息{}",s);
        try {
       //TODO business todo
        }catch (Exception e){
            e.printStackTrace();
            log.info("增加积分失败!!!!!,message的id为{},消费异常为{}",msgId,e);
            return Action.ReconsumeLater;
        }

        return Action.CommitMessage;
    }
}
